﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using DrugStorehouseMIS.DAL;
using DrugStorehouseMIS.Comm;
using DrugStorehouseMIS.DAL.Interface;

namespace DrugStorehouseMIS.BLL
{
    public class Producter
    {

        #region 封装属性

        private int mProducterNum;

        public int ProducterNum
        {
            get { return mProducterNum; }
            set { mProducterNum = value; }
        }

        private string mProducterName;

        public string ProducterName
        {
            get { return mProducterName; }
            set { mProducterName = value; }
        }

        private string mProducterCode;

        public string ProducterCode
        {
            get { return mProducterCode; }
            set { mProducterCode = value; }
        }

        private string mAddress;

        public string Address
        {
            get { return mAddress; }
            set { mAddress = value; }
        }

        private string mContactPerson;

        public string ContactPerson
        {
            get { return mContactPerson; }
            set { mContactPerson = value; }
        }

        private string mTelephone;

        public string Telephone
        {
            get { return mTelephone; }
            set { mTelephone = value; }
        }

        private string mEmail;

        public string Email
        {
            get { return mEmail; }
            set { mEmail = value; }
        }

        private string mCreditLevel;

        public string CreditLevel
        {
            get { return mCreditLevel; }
            set { mCreditLevel = value; }
        }

        private int mFlagDisable;

        public int FlagDisable
        {
            get { return mFlagDisable; }
            set { mFlagDisable = value; }
        }

        #endregion

        private IProducterDAL producterDAL;

        public Producter()
        {
            producterDAL = Adapter.GetProducter();
        }

        public bool FetchObject(IDataReader dr)
        {
            if (dr.Read())
            {
                mProducterNum = ConvertDataType.CheckFiledInt(dr["producter_num"]);
                mProducterName = ConvertDataType.CheckFiledString(dr["producter_name"]);
                mProducterCode = ConvertDataType.CheckFiledString(dr["producter_code"]);
                mAddress = ConvertDataType.CheckFiledString(dr["address"]);
                mContactPerson = ConvertDataType.CheckFiledString(dr["contact_person"]);
                mTelephone = ConvertDataType.CheckFiledString(dr["telephone"]);
                mEmail = ConvertDataType.CheckFiledString(dr["email"]);
                mCreditLevel = ConvertDataType.CheckFiledString(dr["credit_level"]);
                mFlagDisable = ConvertDataType.CheckFiledInt(dr["flag_disable"]);
                dr.Close();
                return true;
            }
            dr.Close();
            return false;
        }
        public DataTable Display()
        {
            return producterDAL.Select();
        }

        public bool CreateProducter(Producter producter)
        {
            return producterDAL.Insert(producter.mProducterName, producter.mProducterCode, producter.mAddress, producter.mContactPerson, producter.mTelephone, producter.mEmail, producter.mCreditLevel, producter.mFlagDisable) > 0 ? true : false;
        }

        public bool SetProducter(Producter producter)
        {
            return producterDAL.Update(producter.mProducterNum, producter.mProducterName, producter.mProducterCode, producter.mAddress, producter.mContactPerson, producter.mTelephone, producter.mEmail, producter.mCreditLevel, producter.mFlagDisable) > 0 ? true : false;
        }

        public bool RemoveProducter(int producterNum)
        {
            return producterDAL.Delete(producterNum) > 0 ? true : false;
        }
    }
}
